<?php
// +----------------------------------------------------------------------
// | Author: yaoyihong <510974211@qq.com>
// +----------------------------------------------------------------------
namespace app\common\controller;

use \tpfcore\Core;
use think\App;

class ApiBase extends ControllerBase
{
	public $api_version;
	protected $platform;
	public function __construct(App $app){
		header("Access-Control-Allow-Origin: *");
		header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
		header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept,Access-Token,Auth-Token,Timestamp,Content-Language,Accept,Accept-Language,platform,api-version");
		parent::__construct($app);
		$request = request();
		
		// 如果header中有api-version就取当中的数据作为版本号，否则就取api_version参数值，默认为1.0.0
		$this->api_version =!empty($request->header('api-version'))?$request->header('api-version'):(isset($this->param['api_version'])?$this->param['api_version']:"1.0.0"); 	// 设置默认版本号为1.0.0

		$this->api_version = preg_replace("/(\d).(\d).(\d)/", "$1.$2", $this->api_version);				// 取前面两位作为版本号

		$this->platform = $request->header('platform');													// 获取当前平台

		$excludeValidateTokenMethodList = isset($this->excludeValidateTokenMethodList)?$this->excludeValidateTokenMethodList:[];
		if(!in_array(ACTION_NAME, $excludeValidateTokenMethodList)){
			$result = Core::loadModel("ApiBase","common","logic")->api_init($this->param);
			$result[0]!=0 && $this->jump($result);
		}
	}
}